feedback-vos 1.0.39 → 1.0.40
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +40 -14
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +40 -14
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -387,24 +387,52 @@ function ScreenshotButton({
|
|
|
387
387
|
const themeClasses = getThemeClasses(theme);
|
|
388
388
|
async function handleTakeScreenshot() {
|
|
389
389
|
setIsTakenScreenShot(true);
|
|
390
|
-
const canvas = await html2canvas__default.default(document.
|
|
390
|
+
const canvas = await html2canvas__default.default(document.documentElement, {
|
|
391
391
|
width: window.innerWidth,
|
|
392
392
|
height: window.innerHeight,
|
|
393
|
-
|
|
394
|
-
|
|
393
|
+
x: 0,
|
|
394
|
+
y: 0,
|
|
395
395
|
windowWidth: window.innerWidth,
|
|
396
396
|
windowHeight: window.innerHeight,
|
|
397
|
-
scale:
|
|
398
|
-
// Use
|
|
397
|
+
scale: 1,
|
|
398
|
+
// Use scale 1 for consistent sizing
|
|
399
399
|
useCORS: true,
|
|
400
|
-
// Enable CORS for better image rendering
|
|
401
400
|
logging: false,
|
|
402
|
-
// Disable logging for cleaner output
|
|
403
401
|
ignoreElements: (element) => {
|
|
404
402
|
return element.hasAttribute("data-feedback-widget") || element.closest("[data-feedback-widget]") !== null;
|
|
405
403
|
}
|
|
406
404
|
});
|
|
407
|
-
const
|
|
405
|
+
const targetWidth = 1920;
|
|
406
|
+
const targetHeight = 1080;
|
|
407
|
+
const normalizedCanvas = document.createElement("canvas");
|
|
408
|
+
normalizedCanvas.width = targetWidth;
|
|
409
|
+
normalizedCanvas.height = targetHeight;
|
|
410
|
+
const ctx = normalizedCanvas.getContext("2d");
|
|
411
|
+
if (!ctx) {
|
|
412
|
+
setIsTakenScreenShot(false);
|
|
413
|
+
return;
|
|
414
|
+
}
|
|
415
|
+
ctx.imageSmoothingEnabled = true;
|
|
416
|
+
ctx.imageSmoothingQuality = "high";
|
|
417
|
+
const sourceAspect = canvas.width / canvas.height;
|
|
418
|
+
const targetAspect = targetWidth / targetHeight;
|
|
419
|
+
let drawWidth = targetWidth;
|
|
420
|
+
let drawHeight = targetHeight;
|
|
421
|
+
let drawX = 0;
|
|
422
|
+
let drawY = 0;
|
|
423
|
+
if (sourceAspect > targetAspect) {
|
|
424
|
+
drawHeight = targetHeight;
|
|
425
|
+
drawWidth = drawHeight * sourceAspect;
|
|
426
|
+
drawX = (targetWidth - drawWidth) / 2;
|
|
427
|
+
} else {
|
|
428
|
+
drawWidth = targetWidth;
|
|
429
|
+
drawHeight = drawWidth / sourceAspect;
|
|
430
|
+
drawY = (targetHeight - drawHeight) / 2;
|
|
431
|
+
}
|
|
432
|
+
ctx.fillStyle = "#ffffff";
|
|
433
|
+
ctx.fillRect(0, 0, targetWidth, targetHeight);
|
|
434
|
+
ctx.drawImage(canvas, drawX, drawY, drawWidth, drawHeight);
|
|
435
|
+
const base64image = normalizedCanvas.toDataURL("image/png", 1);
|
|
408
436
|
onScreenshotTook(base64image);
|
|
409
437
|
setIsTakenScreenShot(false);
|
|
410
438
|
}
|
|
@@ -754,7 +782,7 @@ async function uploadFileToRepo(token, owner, repo, file, folderPath, defaultBra
|
|
|
754
782
|
return rawUrl;
|
|
755
783
|
}
|
|
756
784
|
async function uploadScreenshotToRepo(token, owner, repo, screenshot, screenshotPath) {
|
|
757
|
-
const compressedScreenshot = await compressScreenshot(screenshot,
|
|
785
|
+
const compressedScreenshot = await compressScreenshot(screenshot, 1920, 0.85);
|
|
758
786
|
const base64Content = compressedScreenshot.includes(",") ? compressedScreenshot.split(",")[1] : compressedScreenshot;
|
|
759
787
|
const repoResponse = await fetch(
|
|
760
788
|
`https://api.github.com/repos/${owner}/${repo}`,
|
|
@@ -856,7 +884,7 @@ async function uploadScreenshotToRepo(token, owner, repo, screenshot, screenshot
|
|
|
856
884
|
console.log(`Screenshot uploaded successfully to: ${rawUrl}`);
|
|
857
885
|
return rawUrl;
|
|
858
886
|
}
|
|
859
|
-
function compressScreenshot(dataUrl, maxWidth =
|
|
887
|
+
function compressScreenshot(dataUrl, maxWidth = 1920, quality = 0.85) {
|
|
860
888
|
return new Promise((resolve, reject) => {
|
|
861
889
|
if (typeof window === "undefined" || typeof document === "undefined") {
|
|
862
890
|
reject(new Error("Screenshot compression only works in browser environments"));
|
|
@@ -871,9 +899,8 @@ function compressScreenshot(dataUrl, maxWidth = 2560, quality = 0.9) {
|
|
|
871
899
|
height = height * maxWidth / width;
|
|
872
900
|
width = maxWidth;
|
|
873
901
|
}
|
|
874
|
-
|
|
875
|
-
canvas.
|
|
876
|
-
canvas.height = height * dpr;
|
|
902
|
+
canvas.width = width;
|
|
903
|
+
canvas.height = height;
|
|
877
904
|
const ctx = canvas.getContext("2d");
|
|
878
905
|
if (!ctx) {
|
|
879
906
|
reject(new Error("Could not get canvas context"));
|
|
@@ -881,7 +908,6 @@ function compressScreenshot(dataUrl, maxWidth = 2560, quality = 0.9) {
|
|
|
881
908
|
}
|
|
882
909
|
ctx.imageSmoothingEnabled = true;
|
|
883
910
|
ctx.imageSmoothingQuality = "high";
|
|
884
|
-
ctx.scale(dpr, dpr);
|
|
885
911
|
ctx.drawImage(img, 0, 0, width, height);
|
|
886
912
|
const compressedDataUrl = canvas.toDataURL("image/jpeg", quality);
|
|
887
913
|
resolve(compressedDataUrl);
|